<?php
/**
 * Amazon地区（基础）
 * (model)
 */

namespace App\Models\Basics;

use Illuminate\Database\Eloquent\Model;
class AmazonArea extends Model
{
    //切换API后删除AmazonArea Model
    protected $table = 'b_amazon_area';

    public $timestamps = false;

    protected $guarded = [];

    public static function options()
    {
        return self::query()->pluck('area','id');
    }

    protected static function boot()
    {
        parent::boot();

        static::deleting(function ($model){
            $count = AmazonCountry::query()->where('area_id',$model->id)->count();
            if($count > 0){
                throw new \Exception('使用中勿删除');
            }
        });
    }
}
